import request from '@/utils/request'
import { downloadFileByType } from '@/utils/util'

const api = {
  scoreCardModelList: '/modelApi/gradeModelManage/modelList',
  versionDetail: '/modelApi/gradeModelManage/versionDetail',
  scoreCardModelStatus: '/modelApi/gradeModelManage/scoreCardModelStatus', // 模型上下线
  scoreCardManageModels: '/modelApi/gradeModelManage/model', // 删除模型
  binningDetail: '/modelApi/binningDetail', // 分箱详情
  scoreCardDownload: '/modelApi/modelManage/scoreCardDownload', // 下载模型
  scoreCardTemplateDownload: '/modelApi/gradeModelManage/downloadTemplate', // 模板下载
  scoreCardModelUpload: '/modelApi/gradeModelManage/model', // 上传模型
  scoreCardVariableDetail: '/modelApi/gradeModelManage/variableDetail', // 变量详情
  // 模型测试
  scoreCardModelCalculate: '/modelApi/scoreCardModelCalculate',
}
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).slice(2)
export function getScoreCardModelList(parameter) {
  return request({
    url: api.scoreCardModelList,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

export function getScoreCardVersionDetail(parameter) {
  return request({
    url: api.versionDetail,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
/**
 * 设置评分卡模型状态(模型上下线)
 */
export function setScoreCardModelStatus(parameter) {
  return request({
    url: api.scoreCardModelStatus,
    method: 'put',
    data: parameter,
    formData: true,
  })
}
/**
 * 删除评分卡模型
 */
export function deleteScoreCardModel(parameter) {
  return request({
    url: api.scoreCardManageModels,
    method: 'delete',
    data: parameter,
    formData: true,
  })
}
/**
 * 下载评分卡模型
 */
export function downloadScoreCardModel(parameter, option) {
  return downloadFileByType(request, api.scoreCardDownload, parameter, option)
}

/**
 * 模板下载
 */
export function templateDownload(parameter, option) {
  return downloadFileByType(request, api.scoreCardTemplateDownload, parameter, option)
}
/**
 * 上传评分卡模型
 */
export function uploadScoreCardModel(parameter) {
  return request({
    url: api.scoreCardModelUpload,
    method: 'post',
    data: parameter,
    'Content-Type': `multipart/form-data; boundary=${boundary}`,
  })
}
/**
 * 变量详情
 */
export function getScoreCardVariableDetail(parameter) {
  return request({
    url: api.scoreCardVariableDetail,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}

/**
 * 分箱详情
 */
export function setBinningDetail(parameter) {
  return request({
    url: api.binningDetail,
    method: 'put',
    data: parameter,
    formData: true,
  })
}
/**
 * 模型测试
 */
export function scoreCardModelCalculate(parameter) {
  return request({
    url: api.scoreCardModelCalculate,
    method: 'get',
    params: parameter,
    headers: {
      'Content-Type': 'application/json;charset=UTF-8',
    },
  })
}
